package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.pojo.Evaluate;
import com.chixing.pojo.Point;
import com.chixing.service.EvaluateService;
import com.chixing.service.PointService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
@Controller
public class EvaluateController {
    @Autowired
    private EvaluateService evaluateService;
    @Autowired
    private PointService pointService;
/*
* 条件：订单id
* 结果：用户id和房源id与评论
* 表：订单表order，评论表evaluate
*/
    @GetMapping("personal_center/{cusId}")
    public ModelAndView getByCusId(HttpSession session){
        ModelAndView mav = new ModelAndView();
        Customer customer = (Customer) session.getAttribute("loginCustomer");
        Integer cusId = customer.getCusId();
       ServerResponse evaluate= evaluateService.getByCusId(cusId);
       mav.addObject("evaluate",evaluate);
       mav.setViewName("users/personal_center");
       return mav;
    }

    @PostMapping("")//订单完成页面
    public ModelAndView save(Evaluate evaluate, Point point){
        ModelAndView mav = new ModelAndView();
        ServerResponse PointServer = pointService.save(point);
        mav.addObject("PointServer",PointServer);
        ServerResponse serverResponse1 =  evaluateService.save(evaluate);
        mav.addObject("serverResponse1",serverResponse1);
        mav.setViewName("");
        return mav;
    }

}
